import { defineStore } from "pinia";
import { ref } from 'vue'

export const usePlanStore = defineStore('plan',()=>{
  const todayPlans = ref([{
    content: '完成创想课表项目',
    time: '2025-5-5',
    isTop: true
  }])

  const setTopPlan = (obj)=>{
    todayPlans.value.unshift({
      content: obj.content,
      time: obj.time,
      isTop: obj.isTop
    })
  }

  const setLastPlan = (obj)=>{
    todayPlans.value.push({
      content: obj.content,
      time: obj.time,
      isTop: obj.isTop
    })
  }

  const editPlan = (index,obj)=>{
    if(index >= 0 && index < todayPlans.value.length){
      todayPlans.value[index] = {
        content: obj.content,
        time: obj.time,
        // isTop: obj.isTop
      }
    }
  }

  return {
    todayPlans,
    setTopPlan,
    setLastPlan,
    editPlan
  }
},
{
  persist: true
}
)